home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 22 / PCPP #22.iso / Quake2 / q2source_12_11 / utils3 / qe4 / points.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-28  |  2.8 KB  |  135 lines

  1.  
  2. #include "qe3.h"
  3.  
  4.  
  5. #define    MAX_POINTFILE    8192
  6. static vec3_t    s_pointvecs[MAX_POINTFILE];
  7. static int        s_num_points, s_check_point;
  8.  
  9. void Pointfile_Delete (void)
  10. {
  11.     char    name[1024];
  12.  
  13.     strcpy (name, currentmap);
  14.     StripExtension (name);
  15.     strcat (name, ".lin");
  16.  
  17.     remove(name);
  18. }
  19.  
  20. // advance camera to next point
  21. void Pointfile_Next (void)
  22. {
  23.     vec3_t    dir;
  24.  
  25.     if (s_check_point >= s_num_points-2)
  26.     {
  27.         Sys_Status ("End of pointfile", 0);
  28.         return;
  29.     }
  30.     s_check_point++;
  31.     VectorCopy (s_pointvecs[s_check_point], camera.origin);
  32.     VectorCopy (s_pointvecs[s_check_point], g_qeglobals.d_xy.origin);
  33.     VectorSubtract (s_pointvecs[s_check_point+1], camera.origin, dir);
  34.     VectorNormalize (dir);
  35.     camera.angles[1] = atan2 (dir[1], dir[0])*180/3.14159;
  36.     camera.angles[0] = asin (dir[2])*180/3.14159;
  37.  
  38.     Sys_UpdateWindows (W_ALL);
  39. }
  40.  
  41. // advance camera to previous point
  42. void Pointfile_Prev (void)
  43. {
  44.     vec3_t    dir;
  45.  
  46.     if ( s_check_point == 0)
  47.     {
  48.         Sys_Status ("Start of pointfile", 0);
  49.         return;
  50.     }
  51.     s_check_point--;
  52.     VectorCopy (s_pointvecs[s_check_point], camera.origin);
  53.     VectorCopy (s_pointvecs[s_check_point], g_qeglobals.d_xy.origin);
  54.     VectorSubtract (s_pointvecs[s_check_point+1], camera.origin, dir);
  55.     VectorNormalize (dir);
  56.     camera.angles[1] = atan2 (dir[1], dir[0])*180/3.14159;
  57.     camera.angles[0] = asin (dir[2])*180/3.14159;
  58.  
  59.     Sys_UpdateWindows (W_ALL);
  60. }
  61.  
  62. void Pointfile_Check (void)
  63. {
  64.     char    name[1024];
  65.     FILE    *f;
  66.     vec3_t    v;
  67.  
  68.     strcpy (name, currentmap);
  69.     StripExtension (name);
  70.     strcat (name, ".lin");
  71.  
  72.     f = fopen (name, "r");
  73.     if (!f)
  74.         return;
  75.  
  76.     Sys_Printf ("Reading pointfile %s\n", name);
  77.  
  78.     if (!g_qeglobals.d_pointfile_display_list)
  79.         g_qeglobals.d_pointfile_display_list = glGenLists(1);
  80.  
  81.     s_num_points = 0;
  82.     glNewList (g_qeglobals.d_pointfile_display_list,  GL_COMPILE);
  83.     glColor3f (1, 0, 0);
  84.     glDisable(GL_TEXTURE_2D);
  85.     glDisable(GL_TEXTURE_1D);
  86.     glLineWidth (4);
  87.     glBegin(GL_LINE_STRIP);
  88.     do
  89.     {
  90.         if (fscanf (f, "%f %f %f\n", &v[0], &v[1], &v[2]) != 3)
  91.             break;
  92.         if (s_num_points < MAX_POINTFILE)
  93.         {
  94.             VectorCopy (v, s_pointvecs[s_num_points]);
  95.             s_num_points++;
  96.         }
  97.         glVertex3fv (v);
  98.     } while (1);
  99.     glEnd();
  100.     glLineWidth (1);
  101.     glEndList ();
  102.  
  103.     s_check_point = 0;
  104.     fclose (f);
  105.     Pointfile_Next ();
  106. }
  107.  
  108. void Pointfile_Draw( void )
  109. {
  110.     int i;
  111.  
  112.     glColor3f( 1.0F, 0.0F, 0.0F );
  113.     glDisable(GL_TEXTURE_2D);
  114.     glDisable(GL_TEXTURE_1D);
  115.     glLineWidth (4);
  116.     glBegin(GL_LINE_STRIP);
  117.     for ( i = 0; i < s_num_points; i++ )
  118.     {
  119.         glVertex3fv( s_pointvecs[i] );
  120.     }
  121.     glEnd();
  122.     glLineWidth( 1 );
  123. }
  124.  
  125. void Pointfile_Clear (void)
  126. {
  127.     if (!g_qeglobals.d_pointfile_display_list)
  128.         return;
  129.  
  130.     glDeleteLists (g_qeglobals.d_pointfile_display_list, 1);
  131.     g_qeglobals.d_pointfile_display_list = 0;
  132.     Sys_UpdateWindows (W_ALL);
  133. }
  134.  
  135.